import {
	request,
	baseUrl
} from "../request.js"

//域名 端口号
//var baseUrl = 'https://wzxlovemzy.com:6001/user'

/**
 * 1，用户发红包
 * @param {Object} res
 */
export function sendPkg(res) {
	return request({
		url: baseUrl + '/redPacketBasic/sendPkg',
		method: 'POST',
		data: {
			userId: uni.getStorageSync('userId'),
			senderName: uni.getStorageSync('nickname'),
			senderHead: uni.getStorageSync('head'),
			amount: res.amount,
			num: res.num,
			title: res.title || '恭喜发财',
			hbType: res.hbType,
			pwd: res.pwd,
			groupId: res.groupId || ''
		}
	})
}


/**
 * 2，根据红包id，查询红包信息
 * @param {Object} hbId
 */
export function queryRedPkgById(hbId) {
	return request({
		url: baseUrl + '/redPacketBasic/queryRedPkgById?hbId=' + hbId,
		method: 'GET'
	})
}

/**
 * 3，单个用户抢红包
 * @param {Object} hbId
 */
export function robByUser(hbId) {
	return request({
		url: baseUrl + '/redPacketBasic/robByUser?hbId=' + hbId + '&userId=' + uni.getStorageSync('userId'),
		method: 'GET'
	})
}

/**
 * 4，查询用户是否已经抢过红包
 * @param {Object} hbId
 */
export function queryUserIsRob(hbId) {
	return request({
		url: baseUrl + '/redPacketBasic/queryUserIsRob?hbId=' + hbId + '&userId=' + uni.getStorageSync(
			'userId'),
		method: 'GET'
	})
}

// export function rob(hbId) {
// 	return request({
// 		url: baseUrl + '/redPacketBasic/rob?hbId=' + hbId + '&userId=' + uni.getStorageSync('userId'),
// 		method: 'GET'
// 	})
// }
/**
 * 5，用户抢红包
 * @param {Object} hbId
 * @param {Object} userId
 * @param {Object} nickname
 */
export function rob(hbId, userId, nickname) {
	return request({
		url: baseUrl + '/redPacketBasic/rob',
		method: 'POST',
		data: {
			hbId,
			userId,
			nickname: nickname || ''
		}
	})
}


/**
 * 6，查询红包记录
 * @param {Object} hbId
 */
export function queryRedPkgRobMessage(hbId) {
	return request({
		url: baseUrl + '/redPacketBasic/queryRedPkgRobMessage?hbId=' + parseInt(hbId) + '&userId=' + uni
			.getStorageSync(
				'userId'),
		method: 'GET'
	})
}

/**
 * 7，查询红包记录
 * @param {Object} res
 */
export function queryRedPkgByRecord(res) {
	return request({
		url: baseUrl + '/redPacketBasic/queryRedPkgByRecord',
		method: 'POST',
		data: {
			userId: uni.getStorageSync('userId'),
			year: res.year,
			queryType: res.queryType,
			page: res.page,
			size: res.size
		}
	})
}